#include "junix.h"

template <typename ValueType=int>
struct Node {
	Node() : next(NULL) { }
	explicit Node(const ValueType& value) : data(value) { }

	ValueType data;
	Node<ValueType> *next;
};

template <
typename ValueType=int,
typename Cmp=std::less<ValueType>
>
class Slist {
	Slist() : head(NULL) { }
	~Slist() { delete head; }

	void list_add(const ValueType& value) {
		Node<ValueType> *n = new Node<ValueType>(value);
		Node<ValueType> *q=head,*p=NULL;
		Cmp cmp;

		if (!q) {
			head = n;
			return;
		}

		if (q && !cmp(value,q->data)) {
			p = q;
			q = q->next;
		}

		if (!q) {
			p->next = n;
		} else {
			p->next = n;
			n->next = q;
		}
	}

	void list_del(Node<ValueType> *x) {
		if (!x) return;
		if (head==x) {
			head = head->next;
			delete x;
			return;
		}

		Node<ValueType> *q=head, *p=NULL;
		while (q && q!=x) {
			p = q;
			q = q->next;
		}

		p->next = x->next;
		delete x;
	}


	Node<ValueType> *head;
};

int main(int argc, char **argv)
{
}
